home *** CD-ROM | disk | FTP | other *** search
- /* Copyright (c) 1985 Martin Nohr and Tom Serface
- * All Rights Reserved
- *
- * Revision Date Description
- * -------- --------- --------------------------------------------
- *
- * Copies files to another directory or file
- *
- */
- #include <stdio.h>
- #include <fileFind.h>
-
- #define EOS '\0'
- #define YES 1
- #define NO 0
-
- main(argc,argv)
- int argc;
- char *argv[];
- {
- int mods, err, dir=NO;
- char fspec[85],directory[85],outFile[85],*where;
- char destination[85], dpath[85];
- struct DataArea DTA;
-
- if(argc < 3)
- usage();
- strcpy(dpath,argv[argc-1]);
-
- /*
- * Build a directory path for the copy to file
- * It must be something like A: or A:\ or A:\xxx\yyy or A:\xxx\yyy\
- */
- if(dpath[strlen(dpath)-1] == '\\') /* Take the \ off the end of the line */
- dpath[strlen(dpath)-1] = EOS;
- if(dpath[strlen(dpath)-1] == ':') {
- strcat(dpath,"\\");
- dir=YES;
- }
- else if(GetMod(dpath,&mods) == 0) { /* Destination File exists */
- if(mods & F_DIRECTORY) {
- strcat(dpath,"\\");
- dir=YES;
- }
- else {
- printf("%s: Already Exists ...\n",dpath);
- exit(2);
- }
- }
- if(!dir && argc > 3)
- usage();
- argc -=2;
- ++argv;
- /*
- * Set up the Data Transfer Address Structure
- */
- SetDta(&DTA);
- while(argc--) {
- strcpy(fspec, *argv++);
- strcpy(directory,fspec);
- if((where=rindex(directory,'\\')) || (where=rindex(directory,':'))) {
- *(where+1)=EOS;
- }
- else {
- directory[0]=EOS;
- }
- if (findFirst(fspec,F_ALL)) {
- do {
- err=YES;
- strcpy(outFile,directory);
- strcat(outFile,DTA.dta_name);
- strcpy(destination,dpath);
- GetMod(outFile,&mods);
- if(mods & F_DIRECTORY) {
- printf("%s: is a Directory ... Skipping\n",outFile);
- continue; /* Skip Directories */
- }
- else if(!dir) {
- printf("Copying %s to %s ...\n",outFile, destination);
- err=copy(outFile,destination);
- }
- else {
- strcat(destination,DTA.dta_name);
- if(GetMod(destination,&mods) == 0) {
- if(mods & F_DIRECTORY)
- printf("%s: Is a Directory ... \n",destination);
- else
- printf("%s: Already Exists ...\n",destination);
- }
- else {
- err=copy(outFile,destination);
- printf("Copying %s to %s ...\n",outFile, destination);
- }
- }
- if(err == NO)
- printf("Couldn't Copy: %s to %s\n",outFile,destination);
- } while (findNext(F_ALL));
- }
- else
- printf("Can't find: %s\n",fspec);
- }
- }
-
- usage()
- {
- printf("Usage: cp filespec filespec filespec directory\n");
- printf(" or cp file file\n");
- exit(1);
- }
-